package main

import (
	"fmt"
	"net/http"
	"time"

	"gitee.com/kobeyyf/apibox/util"
)

func main() {
	// test4()
	test41()
}

func test41() {
	url := "https://nlchain.newlandet.com:9099/api?AppCode=trace&Action=State.Put&Key=%s&Value=%s&ChainCode=trace_fiot"
	url2 := "https://nlchain.newlandet.com:9099/api?AppCode=trace&Action=State.Get&Key=abf&ChainCode=trace_fiot"

	var count int
	pool := make(chan bool, 6)
	for {
		for {
			count++
			pool <- true
			go func() {
				key := util.RandomStr(4)
				resp, err := http.Get(fmt.Sprintf(url, key, util.RandomStr(20)))
				if err == nil {
					resp.Body.Close()
				}
				for j := 0; j < count%3; j++ {
					resp, err = http.Get(url2)
					if err == nil {
						resp.Body.Close()
					}
				}
				time.Sleep(time.Second * time.Duration(count%3))
				<-pool
			}()
		}
	}

}
